package com.itheima.clientAndService01;

public class QuickSortClass {
    public static void main(String[] args) {
        int[] arr = {6, 1, 2, 7, 9, 3, 4, 5, 10, 8};
        quickSort(arr,0,arr.length - 1);
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1){
                System.out.println(arr[i] + "]");
            }else {
                System.out.print(arr[i] + ",");
            }
        }
    }

    private static void quickSort(int[] arr,int left, int right) {
        if (left > right) {
            return;
        }
        int left0 = left;
        int right0 = right;
        int Basenumber = arr[left0];

        while (left != right){
            while (arr[left] <= Basenumber && left < right){
                left++;
            }
            while (arr[right] >= Basenumber && left < right) {
                right--;
            }
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }
        int temp = arr[left];
        arr[left] = arr[left0];
        arr[left0] = temp;

        quickSort(arr,left0,left-1);
        quickSort(arr,left+1,right0);
    }
}
